package com.awakensoftware.hunterserver.transformers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.awakensoftware.communicationprotocol.contractobjects.treasures.TreasureTemplateContractObject;
import com.awakensoftware.hunterserver.serverentities.TreasureTemplate;

@Component("treasureTemplateTransformer")
public class TreasureTemplateTransformer extends TransformerBase<TreasureTemplate, TreasureTemplateContractObject> {

	@Autowired
	private TreasureTransformer treasureTransformer;

	@Override
	public TreasureTemplate transformFromContractToServerEntity(TreasureTemplateContractObject contractObject) {
		TreasureTemplate serverEntity = super.tryGetExistingServerEntityById(contractObject.getInternalId());
		if (serverEntity == null) {
			serverEntity = new TreasureTemplate();
		}
		super.doCompleteTransformFromContractObjectToServerEntity(contractObject, serverEntity);
		return serverEntity;
	}

	@Override
	public TreasureTemplateContractObject transformFromServerEntityToContractObject(TreasureTemplate serverEntity) {
		TreasureTemplateContractObject contractObject = new TreasureTemplateContractObject();
		super.doCompleteTransformFromServerEntityToContractObject(contractObject, serverEntity);
		return contractObject;
	}

	@Override
	protected void doTypeSpecificTransformFromContractObjectToServerEntity(
			TreasureTemplateContractObject contractObject, TreasureTemplate serverEntity) {
		if (contractObject.getTreasureInstance() != null) {
			serverEntity.setTreasureInstance(treasureTransformer.transformFromContractToServerEntity(contractObject
					.getTreasureInstance()));
		}
	}

	@Override
	protected void doTypeSpecificTransformFromServerEntityToContractObject(
			TreasureTemplateContractObject contractObject, TreasureTemplate serverEntity) {
		if (serverEntity.getTreasureInstance() != null) {
			contractObject.setTreasureInstance(treasureTransformer
					.transformFromServerEntityToContractObject(serverEntity.getTreasureInstance()));
		}

	}

}
